package ModelLayer;
import java.util.ArrayList;

/**
 * Write a description of class DVDContainer here.
 * 
 * @author Rasmus Andersen Borup 
 * @version 
 */
public class DVDContainer
{
    // instance variables
    private ArrayList<DVD> dvds;
    private static DVDContainer instance;
    
    /**
     * Constructor for objects of class DVDContainer
     */
    private DVDContainer()
    {
        // initialising instance variables
        dvds = new ArrayList<DVD>();
    }
    
    /**
     * Returns an instance of the DVDContainer class if one is not allready made
     */
    public static DVDContainer getInstance()
    {
        if(instance == null)
        {
            instance = new DVDContainer();
        }
        return instance;
    }
    
    public void changeTitle(int dvdId, String title)
    {
        getDvd(dvdId).setTitle(title);
    }
    
    public void changeAquireDate(int dvdId, String aquireDate)
    {
        getDvd(dvdId).setAquireDate(aquireDate);
    }
    
    public void changeAquirePrice(int dvdId, double aquirePrice)
    {
        getDvd(dvdId).setAquirePrice(aquirePrice);
    }

    /**
     * Adds an object of type DVD to the dvds list
     */
    public void addDvd(DVD dvd)
    {
        dvds.add(dvd);
    }
    
    /**
     * Removes an object from the dvds list by comparing values of dvdId
     */
    public void removeDvd(int dvdId)
    {
        DVD dvd = getDvd(dvdId);
        dvds.remove(dvd);
    }

    public DVD getDvd(int dvdId)
    {
        boolean found = false;
        int i = 0;
        DVD wantedDvd = null;
        while(!found && i < dvds.size())
        {
            if(dvds.get(i).getDvdId() == dvdId)
            {
                wantedDvd = dvds.get(i);
                found = true;
            }
            else
            {
                i++;
            }
        }
        return wantedDvd;
    }
    
    public ArrayList<DVD> getDvds()
    {
        return dvds;
    }
    
    public void printInfo(int dvdId)
    {
        getDvd(dvdId).printInfo();
    }
    
    public void printAllDvdInfo()
    {
        for(DVD dvd : dvds)
        {
            dvd.printInfo();
            System.out.println();
        }
    }
}
